Lamp = Widget.extend({
	ctor:function(){
		this._super();
		this.loadLamp();
		this.setTag(TAG_LAMP);
	},
	loadLamp : function(){
		this.setCascadeOpacityEnabled(true);
		var lamp = new Button(this, 7, TAG_JIUJINGDENG, "#jiujingdeng2.png",this.callback);
		lamp.setCascadeOpacityEnabled(true);
		var lid = new Button(this, 10, TAG_DENGMAO, "#dengmao.png",this.callback);
		lid.setPosition(0, 25);
		var huo = new Button(this, 10, TAG_HUOCHAI, "#huochai.png",this.callback);
		huo.setPosition(-200, 0);
		huo.setScale(0.1);
	},
	loadFire : /**
	 * 点火
	 */
		function(){
		var fire = new cc.Sprite("#fire2/1.png");
		fire.setPosition(27, 76);
//		fire.setScale(0.2);
		this.getChildByTag(TAG_JIUJINGDENG).addChild(fire, 7, TAG_LAMP_FIRE);

		var animFrames = [];
		for (var i = 1; i < 4; i++) {
			var str = "fire2/" + i + ".png";
			var frame = cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation = new cc.Animation(animFrames, 0.05);
		var action = cc.animate(animation);
		var repeat = cc.repeatForever(action);
		fire.runAction(repeat);
	},
	callback:function(p){
		var func = cc.callFunc(this.actionDone, this);
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_JIUJINGDENG:
			if(action==ACTION_DO1){
				var mov=cc.moveTo(0.6, cc.p(20,117));
				var move1=cc.moveTo(0.6,cc.p(14,126));
				var move2=cc.moveTo(0.6,cc.p(30,116))
				var seq=cc.sequence(mov,move1,move2,move1,move2,cc.callFunc(function() {
					var show=new ShowTip("当反应生成的光扩展至整支试管时，\n立即停止加热，反应方程式为:Fe + S  ≜  FeS",cc.p(1000,300));
					var wood=ll.run.getChildByTag(TAG_WOOD);
					wood.runAction(cc.moveTo(0.6,cc.p(469,260)));
				}, this),mov,cc.callFunc(function() {
					var s=ll.run.getChildByTag(TAG_TUBE).getChildByTag(TAG_TESTTUBE).getChildByTag(TAG_FILTER_S);
					s.runAction(cc.fadeOut(1));
					var fe=ll.run.getChildByTag(TAG_TUBE).getChildByTag(TAG_TESTTUBE).getChildByTag(TAG_FILTER_FE);
					fe.runAction(cc.spawn(cc.scaleTo(1, 0.5, 1),cc.moveTo(1, cc.p(26,28))));
				}, this),cc.delayTime(1.5),func);
				p.runAction(seq);
			}else if(action==ACTION_DO2){
				var wood=ll.run.getChildByTag(TAG_WOOD);
				wood.runAction(cc.sequence(cc.moveTo(0.6,cc.p(269,260)),cc.callFunc(function() {
					wood.removeFromParent();
				}, this)));			
				var move=cc.moveTo(0.6, cc.p(0,0));
				var seq=cc.sequence(move,cc.callFunc(function() {
					var lid=this.getChildByTag(TAG_DENGMAO);
					var ber1 = cc.bezierBy(1,[cc.p(20,110),cc.p(30,85),cc.p(70,75)]);
					var ber2 = cc.bezierBy(1,[cc.p(-30,60),cc.p(-40,70),cc.p(0,0)]);
					var seq=cc.sequence(ber1,cc.callFunc(function() {
						var fire=this.getChildByTag(TAG_JIUJINGDENG).getChildByTag(TAG_LAMP_FIRE);
						fire.setVisible(false);
					}, this),cc.delayTime(0.3),cc.callFunc(function() {
						var show=new ShowTip("熄灭酒精灯需要盖两次灯帽，\n试管静置，直到冷却",cc.p(250,340));				
					}, this),ber2);
					lid.runAction(seq);
				}, this),cc.delayTime(2.5),cc.callFunc(function() {
					gg.flow.next();
					this.removeFromParent();
				}, this));
				p.runAction(seq);
			}
			break;
		case TAG_DENGMAO:
			var ber = cc.bezierBy(1,[cc.p(-20,60),cc.p(-30,20),cc.p(-70,-70)]);
			var seq=cc.sequence(ber,func);
			p.runAction(seq);
			break;
		case TAG_HUOCHAI:
			var huo=new cc.Sprite("#huochai3.png");
			huo.setPosition(-200,-10);
			huo.setScale(0.25);
			this.addChild(huo,11);
			var move=cc.moveTo(1, cc.p(0,30));	
			var fad=cc.fadeOut(0);
			var seq=cc.sequence(move,fad,func);
			huo.runAction(seq);
			break;
		default:
			break;
		}
	},
	actionDone:function(p){
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_JIUJINGDENG:			
			gg.flow.next();				
			break;
		case TAG_DENGMAO:
			gg.flow.next();
			break;
		case TAG_HUOCHAI:
			gg.flow.next();
			p.removeFromParent();
			break;
		case TAG_DEFAULT:
			var huo=this.getChildByTag(TAG_HUOCHAI);
			this.loadFire();
			huo.setVisible(false);
			gg.flow.next();
			break;
		}
	}
});
